var mongoose = require("mongoose")

mongoose.connect("mongodb://127.0.0.1:27017/manage",function () {
	console.log("数据连接成功......")
	
})
//用户管理
var userSchema = new mongoose.Schema({
	name:String,
	pwd:String,
	nickname:String,
	role:String,
	department:String,
	isflag:String,
	num:Number
})
//进货
var stockSchema = new mongoose.Schema({
	number:String,//单据编号
	rknumber:String,//入库编号
	num:Number,//序号
	supplier:String,//供应商单位名称
	foodname:String,//食材名称/供货品类
	quantity:Number,//食材数量
	quantity2:Number,//已送食材数量
	quantity3:Number,//本次送食材数量
	quantity4:Number,//本次签收食材数量
	company:String,//食材单位
	budget:Number,//预算单价
	budmoney:Number,//预算金额
	remarks:String,//进货备注
	money:Number,//进货金额
	isflag:String,//审核状态
	newtime:String,//进货时间
	signtime:String,//签收时间/入库
	delnumber:String,//送货单编号
	state:String,//签收状态
	signed:String,//签收人/采购人
	signrem:String,//签收备注
	supplierid:String,//供应商单位地址
	supname:String,//联系人/送货人
	tele:String,//联系电话
	endname:String,//结算户名
	endbank:String,//结算银行
	endnumber:Number,//结算账号
	verifier:String,//验证人
	custodian:String,//保管人
	staterk:String,//入库状态
	remarksrk:String//入库备注
})

//日志集合
//管理员用户名	操作说明	操作时间	操作结果	IP
var logSchema = new mongoose.Schema({
	username:String,
	explain:String,
	ctime:String,
	result:String,
	ip:String
})


//基础数据
var baseSchema = new mongoose.Schema({
	tbunitname:String, //单位名称
	tbshortcode:String, //简码
	tbaddress:String,  //单位地址
	tbcontact:String, //联系人
	tbtel:Number, //联系电话
	tbclass:String, //供货种类
	tbusername:String, //结算户名	
	tbbank:String, //结算银行
	tbbanknum:Number, //结算账号
	tbsort:Number,  //排序
})

//菜品管理 
var foodSchema = new mongoose.Schema({
	fdname:String, //菜名
	fdothername:String, //别名
	fdshortcode:String,  //简码
	fdExp:String, //保质期
	fdclass:String, //商品分类
	fdunit:String, //计量单位
	fdaddress:String, //供货单位
	fdFactory:String, //生产厂家
})

//菜品分类
var foodclassSchema = new mongoose.Schema({
	fdclassname:String, //类型名称
	isflag:String, //是否启用
	fdclass:String, //商品种类
	fdclasssort:Number, //排序

})
/* 模块2：供货管理 */
//2.1送货单管理
var sendSchema = new mongoose.Schema({
    sendunit:String, //送货单位
    purchase:String, //采购单位
    fdname:String,  //食材名称
    sendNum:Number, //供货数量
    sendprice:Number, //单价
    allprice:Number, //金额小计
    signname:String, //签收人
    signStatus:String, //签收状态
    signRemarks:String, //签收备注
    settlementName:String, //结算户名
    settlementBank:String, //结算银行
    settlementNum:Number, //结算账号
    billnumdata:String, //单据编号日期
    billnum:String, //单据编号
    billdate:String, //签收日期
})

//2.2 收款单管理
var receiveSchema = new mongoose.Schema({
    sendunit:String, //送货单位
    purchase:String, //采购单位
    fdname:String,  //食材名称
    sendNum:Number, //供货数量
    sendprice:Number, //单价
    allprice:Number, //金额小计
    signname:String, //签收人
    signStatus:String, //签收状态
    signRemarks:String, //签收备注
    settlementName:String, //结算户名
    settlementBank:String, //结算银行
    settlementNum:Number, //结算账号
    billnumdata:String, //单据编号日期
    billnum:String, //单据编号
    billdate:String, //签收日期
})


//日志管理
global.logmodel = mongoose.model("log",logSchema,"log");
//用户管理
global.usermodel = mongoose.model("user",userSchema,"user");
//进货
global.stockmodel = mongoose.model("stock",stockSchema,"stock");
//基础数据
global.basemodel = mongoose.model("base",baseSchema,"base");
//菜品管理
global.foodmodel = mongoose.model("food",foodSchema,"food");
//菜品分类
global.foodclassmodel = mongoose.model("foodclass",foodclassSchema,"foodclass");
//送货单管理
global.sendmodel = mongoose.model("send",sendSchema,"send");
//收款单管理
global.receivemodel = mongoose.model("receive",receiveSchema,"receive");


/*
db.stock.insert({"aid":1,"bid":1, "num" : 1, "supplier" : "元祖月饼", "foodname" : "猪肉", "quantity" : 1, "company" : "升", "budget" : 23, "remarks" : " 多少有点肉"})
db.stock.insert({"aid":1,"bid":2 ,"num" : 1, "supplier" : "元祖月饼", "foodname" : "猪肉", "quantity" : 1, "company" : "升", "budget" : 23, "remarks" : " 多少有点肉"})
db.stock.insert({"aid":1,"bid":3 ,"num" : 1, "supplier" : "元祖月饼", "foodname" : "猪肉", "quantity" : 1, "company" : "升", "budget" : 23, "remarks" : " 多少有点肉"})
db.stock.insert({"aid":2,"bid":1, "num" : 1, "supplier" : "元祖月饼", "foodname" : "猪肉", "quantity" : 1, "company" : "升", "budget" : 23, "remarks" : " 多少有点肉"})
db.stock.insert({"aid":2,"bid":2, "num" : 1, "supplier" : "元祖月饼", "foodname" : "猪肉", "quantity" : 1, "company" : "升", "budget" : 23, "remarks" : " 多少有点肉"})
db.stock.insert({"aid":2,"bid":3 ,"num" : 1, "supplier" : "元祖月饼", "foodname" : "猪肉", "quantity" : 1, "company" : "升", "budget" : 23, "remarks" : " 多少有点肉"})

*/